<?php 


function testMongoDB(){


	$manager = new MongoDB\Driver\Manager("mongodb://localhost:27017");

	$filter=["userLevel"=>2];  //条件
	$options=["sort"=>["mobile"=>1]]; //排序和其它
	// $filter=[];
	// $options=[];
	$query=new MongoDB\Driver\Query($filter,$options);

	$cursor = $manager->executeQuery('runoobdb.byrgPhone',$query);
	$arr = array(); //将所有的数据先取出来
	foreach($cursor as $document){
		array_push($arr,(array)$document);

	}

	echo '<pre>';

		var_dump($arr);

	echo '</pre>';



}

function getriqiBaobiao($starDate,$endDate){ //按日期获取报表的

	$toke = 'Cookie: '.json_decode(getDb('select toke from toke where name_i="bjrg"'))->data[0]->toke;
	$url = 'https://aicrm.byai.com/datacenter/csStaff/date/stat';
	$params =['startDate'=>$starDate,'endDate'=>$endDate];

	$header = array(
                'X-AjaxPro-Method:ShowList',
                'Content-Type: application/json; charset=utf-8',
                $toke);

	$arr=php_do_Url_GET($url,$params,$header);
	$arr['code']=0;
	$arr['count']=count($arr['data']);

	return json_encode(
		$arr,
		JSON_UNESCAPED_UNICODE
	);


}


function getBaobiao($starDate,$endDate){ //获取报表的api接口

	$toke = 'Cookie: '.json_decode(getDb('select toke from toke where name_i="bjrg"'))->data[0]->toke;
	$url = 'https://aicrm.byai.com/datacenter/csStaff/seat/stat';
	$params =['startDate'=>$starDate,'endDate'=>$endDate];

	$header = array(
                'X-AjaxPro-Method:ShowList',
                'Content-Type: application/json; charset=utf-8',
                $toke);

	$arr=php_do_Url_GET($url,$params,$header);
	$arr['code']=0;
	$arr['count']=count($arr['data']);

	return json_encode(
		$arr,
		JSON_UNESCAPED_UNICODE
	);


	//https://aicrm.byai.com/datacenter/csStaff/date/stat?startDate=2021-03-08&endDate=2021-03-09
	
}

function getDateAll($userLevel){  //获取全部A客数据

	$manager = new MongoDB\Driver\Manager("mongodb://localhost:27017");

	$filter=["userLevel"=>(int)$userLevel];  //条件
	$options=["sort"=>["updatedAt"=>-1],"limit"=>$_GET['limit'],"skip"=>($_GET['page']-1)*$_GET['limit']]; //排序和其它
	// $filter=[];
	// $options=[];
	$query=new MongoDB\Driver\Query($filter,$options);

	$cursor = $manager->executeQuery('runoobdb.byrgPhone',$query);
	$arr = array(); //将所有的数据先取出来
	foreach($cursor as $document){
		array_push($arr,(array)$document);

	}

	return json_encode(

		[	'code'=>0,
			"msg"=>"获取数据成功",
			'count'=>getDateAllCount($userLevel),
			'data'=>$arr
		],
		JSON_UNESCAPED_UNICODE
	);
}

function getDateAllCount($userLevel){ //计数功能



	$manager = new MongoDB\Driver\Manager("mongodb://localhost:27017");

	$filter=["userLevel"=>(int)$userLevel];  //条件
	$options=[]; //排序和其它
	// $filter=[];
	// $options=[];
	$query=new MongoDB\Driver\Query($filter,$options);

	$cursor = $manager->executeQuery('runoobdb.byrgPhone',$query);
	$arr = array(); //将所有的数据先取出来
	foreach($cursor as $document){
		array_push($arr,(array)$document);

	}

	return count($arr);

}


function getDateAllMySql(){ //用mysql数据库的方式获取

	
	$limit = $_GET['limit'] && $_GET['page']?$_GET['limit']:null;

	switch ($_GET['fenpei']) {
		case '1':
			$fenpei ='WHERE b.customerId IS NULL';
			break;
		case '0':
			$fenpei ='WHERE b.customerId IS NOT NULL';
			break;
		case 'all':
			$fenpei ='';
			break;
		default:
			$fenpei ='WHERE b.customerId IS NOT NULL';
			break;
	}

	$qure = "SELECT a.customerId,a.mobile,a.contactName,a.updatedAt,IF(b.name='test-lx','B库',IF(b.name='591-lx','A库','')) AS qudao FROM(

				SELECT a.customerId,a.mobile,a.contactName,a.updatedAt FROM (
				SELECT customerId,mobile,contactName,updatedAt FROM linxidb.customers WHERE userLevel={$_GET['userLevel']} AND updatedAt BETWEEN '{$_GET['starDate']}' AND '{$_GET['endDate']}') a
				LEFT JOIN 
				linxidb.customer_yunweinames b
				ON a.customerId = b.customerId
				{$fenpei}

			)a LEFT JOIN (SELECT link_url,NAME FROM weizandata.youjutell WHERE NAME IN ('test-lx','591-lx')) b ON a.mobile = b.link_url ORDER BY a.updatedAt DESC";
	
	if($limit){

		$skip = ($_GET['page']-1)*$_GET['limit'];

		$qure .= " LIMIT {$_GET['limit']} OFFSET {$skip};";
	}


	// $qurecount = "SELECT COUNT(*) AS ct FROM linxidb.customers WHERE userLevel={$_GET['userLevel']} AND updatedAt BETWEEN '{$_GET['starDate']}' AND '{$_GET['endDate']}';";


	$qurecount = "SELECT COUNT(*) as ct FROM 
					(SELECT  customerId FROM linxidb.customers WHERE userLevel={$_GET['userLevel']} AND updatedAt BETWEEN '{$_GET['starDate']}' AND '{$_GET['endDate']}')
					a
					LEFT JOIN 
					linxidb.customer_yunweinames b
					ON a.customerId = b.customerId
					{$fenpei};";


	$count = json_decode(getDb($qurecount))->data[0]->ct;
	
	$res = json_decode(getDb($qure));

	$res->count = $count;

	return json_encode($res,JSON_UNESCAPED_UNICODE);

}





function aggregate(){ //按等级客服日期分组查询

	$manager = new MongoDB\Driver\Manager("mongodb://localhost:27017");
	$param = [
	    'aggregate' => 'byrgPhone',
	    'pipeline' => [
	        
	        ['$group' => ['_id' => ['userLevel'=>'$userLevel','followerName'=>'$followerName','createdAt'=>['$substr'=>array('$createdAt',0,10)]  ]
	        			,'hr_count' => ['$sum' => 1]]]
	    ],
	    'cursor'=>new stdClass,

	];
	$cmd = new MongoDB\Driver\Command($param);
	$cursor=$manager->executeCommand('runoobdb', $cmd);
	$arr=array();
	foreach ($cursor as $key => $document) {
		
		$document->_id->hr_count = $document->hr_count;

		array_push($arr,$document->_id);
	}

	return json_encode(

		[	'code'=>0,
			"msg"=>"获取数据成功",
			'count'=>count($arr),
			'data'=>$arr
		],
		JSON_UNESCAPED_UNICODE
	);
}


function getABku(){

	$issetLimit =  $_GET['limit']?true:false;



	$qure = "SELECT title,start_date,NAME,link_url FROM youjutell WHERE NAME IN ".$_GET['ABku']." AND start_date BETWEEN '".$_GET['starDate']."' AND '".$_GET['endDate']."' LIMIT ".$_GET['limit']." OFFSET ".($_GET['page']-1)*$_GET['limit'] .";";


	$qureCount = "SELECT count(*) as count FROM youjutell WHERE NAME IN ".$_GET['ABku']." AND start_date BETWEEN '".$_GET['starDate']."' AND '".$_GET['endDate']."';";

	if(!$issetLimit){

		$qure = "SELECT title,start_date,NAME,link_url FROM youjutell WHERE NAME IN ".$_GET['ABku']." AND start_date BETWEEN '".$_GET['starDate']."' AND '".$_GET['endDate']."'";
	}


	$count = json_decode(getDb($qureCount))->data[0]->count;
	
	$res = json_decode(getDb($qure));

	$res->count = $count;

	return json_encode($res,JSON_UNESCAPED_UNICODE);


}


function getbyRemark(){


	$toke = 'Cookie: '.json_decode(getDb('select toke from toke where name_i="bjrg"'))->data[0]->toke;

	$header = array(
                'X-AjaxPro-Method:ShowList',
                'Content-Type: application/json; charset=utf-8',
                $toke);

	$customer = $_GET['customer'];
	$params = ['customerId'=>$customer,'pageSize'=>30,'pageNum'=>1];
	$url = 'https://crm.byai.com/api/customer/listFollowRecordPage';

	$remark = php_do_Url_GET($url,$params,$header);

	return json_encode($remark,JSON_UNESCAPED_UNICODE);

}


function importExcel(){

	//POST参数   * fields 列名与key值的键值对 * data 传过来的表格内容数组  *tableName 表格的名称

	ini_set("display_errors", "On");

	$fields = $_POST['fields'];

	$arr = json_decode($_POST['data'],true);


	$excelField=array();

	for ($i=0; $i <count($fields) ; $i++) { 
		
		$excelField[$fields[$i]['field']]=$fields[$i]['title'];
	}


	$newRow = array();

	for ($j=0; $j <count($arr) ; $j++) {

		foreach ($excelField as $key => $value) {
			
			$newRow[$j][$key]=$arr[$j][$key];

		}

	}

	require_once 'C:\phpstudy_pro\WWW\cscs.qumei.com\weizanZB\PHPExcel-1.8\Classes\PHPExcel.php';

	$objPHPExcel=new PHPExcel();
	
	array_unshift($newRow,$excelField);

	$objPHPExcel->getActiveSheet()->fromArray($newRow);

	$objWriter =PHPExcel_IOFactory:: createWriter($objPHPExcel, 'Excel2007');

	$nameFile=$_POST['tableName'].date("Ymd");

	$objWriter->save(__DIR__."\\excel\\".$nameFile.".xlsx");  // //excel/二维码.xlsx


	echo "excel\\".$nameFile.".xlsx";

}

function getYunWei(){

	$qure = "SELECT userId,name FROM linxidb.users WHERE titleId in ('yunwei')  AND on_the_job=1;";

	return getDb($qure);
}

function insertCustomer_yunweinames(){ //插入运维表数据

	$customer_status = $_GET['customer_status']==null?3:$_GET['customer_status'];

	$qure = "INSERT INTO linxidb.customer_yunweinames (customerId,yunweiId,updatetime,customer_QCId,followUserName,Reasons_for_disqualification,customer_status) VALUE ('{$_GET['customerId']}','{$_GET['yunweiId']}','{$_GET['updatetime']}','{$_GET['QCId']}','{$_GET['followUserName']}','{$_GET['Reasons_for_disqualification']}','{$customer_status}');";

	return insertintoDb($qure);

}


function getKeFunFenPeiTable(){


	$limit = $_GET['limit'] && $_GET['page']?$_GET['limit']:null;


	$userId = $_GET['userId']=='all'?'%':$_GET['userId'];

	$status = $_GET['status']=='all'?'%':$_GET['status'];

	$mobile = $_GET['mobile']=='all'?'%':$_GET['mobile'];

	// $yuweiId =$_GET['yuweiId']=='all'?'%':$_GET['yuweiId'];

	$qure="
		SELECT a.customerId,a.yunweiId,a.updatetime,a.customer_status,a.followUserName,a.mobile,a.contactName,a.Reasons_for_disqualification,IF(a.name='test-lx','B库',IF(a.name='591-lx','A库','')) AS qudao,b.name FROM(
		SELECT a.customerId,a.yunweiId,a.updatetime,a.customer_status,a.followUserName,a.mobile,a.contactName,b.name,a.Reasons_for_disqualification FROM(
		SELECT a.customerId,a.yunweiId,a.updatetime,a.customer_status,a.followUserName,b.mobile,b.contactName,a.Reasons_for_disqualification FROM 
		(SELECT * FROM linxidb.`customer_yunweinames` WHERE yunweiId LIKE '{$userId}' AND updatetime BETWEEN '{$_GET['starDate']}' AND '{$_GET['endDate']}' AND customer_status LIKE '{$status}') a
		LEFT JOIN
		linxidb.`customers` b
		ON a.customerId = b.customerId WHERE b.mobile LIKE '{$mobile}')a
		LEFT JOIN 
		(SELECT * FROM
		weizandata.youjutell WHERE NAME IN ('test-lx','591-lx'))b
		ON a.mobile = b.link_url)a
		LEFT JOIN
		linxidb.users b
		ON a.yunweiId = b.userId
		ORDER BY a.updatetime DESC
	";


	// echo $qure;

	$qurecount = "
		SELECT COUNT(*) as ct FROM linxidb.`customer_yunweinames` WHERE yunweiId like '{$userId}' AND updatetime BETWEEN '{$_GET['starDate']}' AND '{$_GET['endDate']}' AND customer_status LIKE '{$status}';
		";



	$qure .=$where;

	if($limit){

		$skip = ($_GET['page']-1)*$_GET['limit'];

		$qure .= " LIMIT {$_GET['limit']} OFFSET {$skip};";
	}


	

	// echo $qurecount;
	// $count = $mobile=="all"?json_decode(getDb($qurecount))->data[0]->ct:1;
	if($mobile == "%"){
		$count = json_decode(getDb($qurecount))->data[0]->ct;
	}else{
		$count =1;
	}
	
	
	$res = json_decode(getDb($qure));

	$res->count = $count;

	return json_encode($res,JSON_UNESCAPED_UNICODE);


}

function updata_yidu(){


	$qure="UPDATE linxidb.customer_yunweinames SET customer_status={$_GET['statusId']} WHERE customerId='{$_GET['customerId']}';";

	// echo $qure;

	return insertintoDb($qure);

}

function updata_customer_yunweinames_status(){

	$Reasons_for_disqualification = $_GET['Reasons_for_disqualification']?$_GET['Reasons_for_disqualification']:'';

	$qure="UPDATE linxidb.customer_yunweinames SET customer_status={$_GET['statusId']},Reasons_for_disqualification = '{$Reasons_for_disqualification}' WHERE customerId='{$_GET['customerId']}';";

	// echo $qure;

	return insertintoDb($qure);


}
function getYunWeiFenPeiCount(){

	$qure="SELECT a.date,b.name,a.count FROM(
		SELECT LEFT(updatetime,10) AS DATE,yunweiId,COUNT(*) AS COUNT FROM linxidb.customer_yunweinames GROUP BY LEFT(updatetime,10),yunweiId) a
		LEFT JOIN linxidb.users b
		ON a.yunweiId = b.userId
		WHERE NAME IS NOT NULL
		AND a.date = CURDATE()
		ORDER BY a.date DESC;";

	return getDb($qure);
}

function getKeFuFenPeiTable(){

	$qure="SELECT a.followUserName,a.customerId,a.mobile,a.Reasons_for_disqualification,a.customer_QCId,a.customer_status,b.name AS yunweiName,a.updatetime FROM(
			SELECT b.followUserName,a.customerId,a.mobile,b.Reasons_for_disqualification,b.customer_QCId,b.customer_status,b.yunweiId,b.updatetime FROM(
			SELECT updatedAt,customerId,mobile FROM linxidb.customers WHERE updatedAt BETWEEN '2021-03-24 00:00:00' AND '2021-03-24 23:59:59' AND userLevel=2) a
			LEFT JOIN linxidb.customer_yunweinames b
			ON a.customerId = b.customerId
			WHERE b.followUserName IS NOT NULL) a
			LEFT JOIN linxidb.users b
			ON a.yunweiId = b.userId
			WHERE a.updatetime BETWEEN '2021-03-24 00:00:00' AND '2021-03-25 23:59:59';";

	return getDb($qure);

}

function getKeFuFenPeiDatilTable(){


	$filltyday = explode("-",$_GET['endDate'])[2]+1;

	$filltyendData =explode("-",$_GET['endDate']);

	$filltyendData[2] = $filltyday;

	$fe=implode("-", $filltyendData);

	$followerName = $_GET['followerName']=="all"?"%":$_GET['followerName'];

	$qure="
		SELECT * FROM(			
		SELECT a.followUserName,a.customerId,a.mobile,a.Reasons_for_disqualification,a.customer_QCId,a.customer_status,b.name AS yunweiName,a.updatetime,a.updatedAt FROM(
		SELECT b.followUserName,a.customerId,a.mobile,b.Reasons_for_disqualification,b.customer_QCId,b.customer_status,b.yunweiId,b.updatetime,a.updatedAt FROM(
		SELECT updatedAt,customerId,mobile FROM linxidb.customers WHERE updatedAt BETWEEN '{$_GET['starDate']} 00:00:00' AND '{$_GET['endDate']} 23:59:59' AND userLevel=2) a
		LEFT JOIN linxidb.customer_yunweinames b
		ON a.customerId = b.customerId
		WHERE b.followUserName LIKE '{$followerName}') a
		LEFT JOIN linxidb.users b
		ON a.yunweiId = b.userId
		WHERE a.updatetime BETWEEN '{$_GET['starDate']} 00:00:00' AND '{$fe} 12:59:59') a
		LEFT JOIN linxidb.customerStatus b
		ON a.customer_status=b.statusId;";


	return getDb($qure);
}

function getKeFuFenPeiCount(){

	

	$filltyday = explode("-",$_GET['endDate'])[2]+1;

	$filltyendData =explode("-",$_GET['endDate']);

	$filltyendData[2] = $filltyday;

	$fe=implode("-", $filltyendData);

	$qure="SELECT a.followUserName,COUNT(*) AS COUNT,SUM(IF(a.customer_status=0,1,0)) AS 'pass',SUM(IF(a.customer_status=1,1,0)) AS zhuandan FROM(
			SELECT b.followUserName,a.customerId,a.mobile,b.Reasons_for_disqualification,b.customer_QCId,b.customer_status,b.yunweiId,b.updatetime FROM(
			SELECT updatedAt,customerId,mobile FROM linxidb.customers WHERE updatedAt BETWEEN '{$_GET['starDate']} 00:00:00' AND '{$_GET['endDate']} 23:59:59' AND userLevel=2) a
			LEFT JOIN linxidb.customer_yunweinames b
			ON a.customerId = b.customerId
			WHERE b.followUserName IS NOT NULL) a
			LEFT JOIN linxidb.users b
			ON a.yunweiId = b.userId
			WHERE a.updatetime BETWEEN '{$_GET['starDate']} 00:00:00' AND '{$fe} 12:00:00' AND a.followUserName='{$_GET['followerName']}'
			GROUP BY a.followUserName
			ORDER BY COUNT DESC;";


	return getDb($qure);
}

function pass(){ //处理不合格变为合格的数据逻辑


	$qure="
		DELETE FROM linxidb.customer_yunweinames WHERE customerId='{$_GET['customerId']}';
	";

	// UPDATE linxidb.customers SET updatedAt='{$_GET['updatedAt']}'  WHERE customerId='{$_GET['customerId']}';

	$qure1="
		UPDATE linxidb.customers SET updatedAt='{$_GET['updatedAt']}'  WHERE customerId='{$_GET['customerId']}';
	";

	insertintoDb($qure);

	return insertintoDb($qure1);

}


function login(){


	$yunwei  = json_decode(getDb("SELECT * FROM linxidb.users a LEFT JOIN linxidb.user_root b ON a.titleId=b.titleId WHERE on_the_job=1;"),true);

	$loginUsername = $_POST['loginUsername'];

	$loginPassword = $_POST['loginPassword'];

	$yanzheng=1;

	$yanzhengUser=0;

	for ($i  = 0 ; $i < $yunwei['msg'] ; $i++){

		$userId = $yunwei['data'][$i]['userId'];

		if($userId==$loginUsername){
			$yanzhengUser=1;
		}

	}

	if($yanzhengUser){

		for ($j  = 0 ; $j < $yunwei['msg'] ; $j++){

			$password = $yunwei['data'][$j]['password'];

			if($password==$loginPassword){

				//启动session的初始化
				session_start();
				//注册session变量，赋值为一个用户的名称
				$_SESSION["username"]=$yunwei['data'][$j]['name'];
				//注册session变量，赋值为一个用户的ID
				$_SESSION["userId"]=$loginUsername;

				$_SESSION['titleId']=$yunwei['data'][$j]['titleId'];

				unset($yunwei['data'][$j]['name']);
				unset($yunwei['data'][$j]['titleId']);
				unset($yunwei['data'][$j]['password']);
				unset($yunwei['data'][$j]['userId']);


				$_SESSION['user_root']=$yunwei['data'][$j];

				echo '{"code":"300","msg":"密码正确"}';

				return;
			}

		}

		echo '{"code":"400","msg":"密码错误"}';

	}else{

		echo '{"code":"400","msg":"用户名不存在"}';
		return;
	}


}

function loginYanZheng(){  //登录验证

	session_start();
	
	if(count($_SESSION)>0){

		$res=[

			'code'=>400,
			'msg'=>'当前已登录',
			'data'=>$_SESSION

		];

		echo json_encode($res,JSON_UNESCAPED_UNICODE);
		 
	}else{

		$res=[

			'code'=>300,
			'msg'=>'当前未登录',
			
		];

		echo json_encode($res,JSON_UNESCAPED_UNICODE);

	}
	
}

function loginZhuXiao(){ //登录注销

	session_start();
	//判断Cookie中是否存在session ID
	if(isset($_COOKIE[session_name()])){
	    //删除包含Session ID的cookie，注意第四个参数一定要和php.ini设置的路径相同
	    setcookie(session_name(),'',time()-3600,'/');
	    echo '{code:400,msg:"注销登录成功"}';
	}else{
		echo '{code:300,msg:"当前未登录"}';
	}


}

function getdetail(){ //获取客户详情

	$Cookie="Cookie:yp_riddler_id=0700e261-281c-489b-b7e4-e9f79347080c; acw_tc=2f624a1316162480033177676e5bb12e2174b91f1b5f6aa3493f5266b080eb; client-name=crm_pc; Hm_lvt_32c1bc0db5aef686eecfda6ac9b996cc=1615469705,1616248003; crm_pc_token=crm_pc_token_414bc96aee6b4ae2bb19e81378fd17c5; Hm_lpvt_32c1bc0db5aef686eecfda6ac9b996cc=1616248025; INDATA-SESSIONID=1ce2f2bb-8b9b-4d30-89a0-dbce12e37cf3; JSESSIONID=47203530CDC33B6E03CC1D7FED048AC0; SESSION=YTYyNDNhNjQtNTU1Ni00NmVhLTk5NTMtNzUxZGEzMTczN2Jh";

	$url="https://crm.byai.com/api/customer/detail";
	$customerId = "2998094145";
	$params=['customerId'=>$customerId];
	$header=['Cookie'=>$Cookie];

	echo "<pre>";
		var_dump(php_do_Url_GET($url,$params,$header));
	echo "</pre>";
} 


function  php_do_url_POST($url,$params,$headers=[]){ //POST get

        $ch = curl_init ();
        curl_setopt ( $ch, CURLOPT_URL, $url );
        curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
        curl_setopt ( $ch, CURLOPT_CUSTOMREQUEST, 'POST' );
        curl_setopt ( $ch, CURLOPT_POSTFIELDS, $params );
        curl_setopt ( $ch, CURLOPT_HTTPHEADER, $headers );
        curl_setopt ( $ch, CURLOPT_TIMEOUT, 60 );
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($ch, CURLOPT_SSLVERSION, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        $json_string = curl_exec ( $ch );
        $data = json_decode($json_string, true);
        curl_close ( $ch );
        return $data;
}

function php_do_Url_GET($url,$params,$header=array()){ //Get get

    $url = "{$url}?" . http_build_query ($params);
    $ch = curl_init ();
    curl_setopt ( $ch, CURLOPT_URL, $url );
    curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
    curl_setopt ( $ch, CURLOPT_CUSTOMREQUEST, 'GET' );
    curl_setopt ( $ch, CURLOPT_TIMEOUT, 60 );
    curl_setopt ( $ch, CURLOPT_POSTFIELDS, $params );
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($ch, CURLOPT_SSLVERSION, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($ch, CURLOPT_HTTPHEADER,$header);
 

    $json_string = curl_exec ( $ch );

    $data = json_decode($json_string, true);

    curl_close ( $ch );

    return $data;
}

function getDb($qure){ //42

	$host='localhost';
	$user='root';
	$password='root';
	$database='weizandata';
	$link=mysqli_connect($host, $user, $password, $database);
	$link->query("set names utf8");
	$result=mysqli_query($link, $qure);
	$arr=mysqli_fetch_all($result, 1);
	$json = json_encode(array(
			"code"=>0,
			"msg"=>count($arr),
			"data"=>$arr),
			JSON_UNESCAPED_UNICODE);

	mysqli_close($link);

	return $json;

}

function insertintoDb($qure){


	$host='localhost';
	$user='root';
	$password='root';
	$database='weizandata';
	$link=mysqli_connect($host, $user, $password, $database);
	$link->query("set names utf8");
	$result=mysqli_query($link, $qure);


	if ($result === TRUE) {

		return $json = json_encode(array(
			"code"=>300,
			"msg"=>'新记录插入成功'
			),
			JSON_UNESCAPED_UNICODE);


	} else {

		return $json = json_encode(array(
				"code"=>400,
				"msg"=>$link->error,
				"qure"=>$qure),
				JSON_UNESCAPED_UNICODE);

	}
	
	mysqli_close($link);


}

?>


